package zev;

import java.util.ArrayList;
import java.util.List;

/**
 * extends:泛型的上限 <= 一般用于限制操作 不能使用在添加数据上，一般都是用于数据的读取
 * supper:泛型的上限 >= 即父类或自身。一般用于下限操作
 * @ProjectName: Learning
 * @Package: zev
 * @ClassName: Demo05
 * @Description: java类作用描述
 * @Author: ZhangZewei
 * @CreateDate: 2018/11/7 23:14
 * @UpdateUser: ZhangZewei
 * @UpdateDate: 2018/11/7 23:14
 * @UpdateRemark: The modified content
 * @Version: 1.0
 */
public class Demo05<T extends Fruit> {

    private static void test01() {
        Demo05<Fruit> t1 = new Demo05<Fruit>();
        Demo05<Apple> t2 = new Demo05<Apple>();
        Demo05<Pear> t3 = new Demo05<Pear>();
    }

    private static void test02(List<? extends Fruit> list) {

    }

    private static void test03(List<? super Apple> list) {

    }

    public static void main(String[] args) {

        // 调用test02(),测试 extends  <=
        test02(new ArrayList<Fruit>());
        test02(new ArrayList<Apple>());
        test02(new ArrayList<ReadApple>());
        // test02(new ArrayList<Object>()); Object 不是 Fruit 的子类 ，编译不通过


        // 调用test03() ,测试super >=
        test03(new ArrayList<Apple>());
        test03(new ArrayList<Fruit>());
        //test03(new ArrayList<ReadApple>());  ReadApple < apple,所以不能放入
    }

}

class Fruit {

}

class Apple extends Fruit {

}

class Pear extends Fruit {

}

class ReadApple extends Apple {

}
